<template>
	<view>
		<view class="user">
			<!-- 头部 -->
			<view class="top">
				<image src="../../static/images/lishi.png"></image>
				<view class="text">浏览历史</view>
			</view>
			<!-- 主题内容 -->
			<view class="content">
				<view class="row" v-for="item in listArr">
					<newsbox :item="item" @click.native="goDetail(item)">
					</newsbox>
				</view>
			</view>
		</view>

		<!-- 当没有缓存记录的时候显示 -->
		<view class="nohistory" v-if="!listArr.length">
			<image src="../../static/images/noData.png" mode="widthFix">
				<view class="text">暂无浏览记录</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				listArr: []
			};
		},
		onShow() {
			this.getData()
		},
		methods: {
			// 跳转到详情页面
			goDetail(item) {
				// 保留跳转之前的页面
				uni.navigateTo({
					url: `/pages/detail/detail?newsId=${item.newsId}`
				})
			},

			// 获取缓存浏览记录
			getData() {
				// uni.getStorageSync() 获取缓存数据
				let hisArr = uni.getStorageSync("historyArr") || []
				this.listArr = hisArr
			}

		}
	}
</script>

<style lang="scss">
	.user {
		.top {
			padding: 50rpx 0;
			background: #f8f8f8;
			color: #555;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			image {
				width: 200rpx;
				height: 200rpx;
			}

			.text {
				font-size: 38rpx;
				padding-top: 20rpx;
			}
		}

		.content {
			padding: 30rpx;

			.row {
				border-bottom: 1px dashed #efefef;
				padding: 15px 0;
			}
		}
	}

	.nohistory {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		image {
			width: 400rpx;
		}

		.text {
			font-size: 25rpx;
			color: #888;
		}
	}
</style>